<?php

class Kd_Html_Toolbar_Group extends Kd_Html_Element {

    private $_items = array();
    private $_name = '';

    public function __construct() {
        parent::__construct();
    }

    public function getName(){
        return $this->_name;
    }
    public function setName($value){
        $this->_name = $value;
        return $this;
    }

    public function getItems() {
        return $this->_items;
    }

    public function addItem(Kd_Html_Element $item) {
        $this->_items[] = $item;
        return $this;
    }

    public function addLabel($text){
        $result = new Kd_Html_Element_Label();
        $result->setText($text);
        return $result;
    }

    public function addButton($text, $type = 'link') {
        switch($type){
            case 'link':
                $result = new Kd_Html_Button_Link();
                break;
            case 'button':
                $result = new Kd_Html_Button_Button();
                break;
        }
        $result->setText($text);
        $this->addItem($result);
        return $result;
    }

    public function addLink($href, $text, $target = '') {
        $result = new Kd_Html_Element_Link();
        $result->setHref($href)->setText($text)->setTarget($target);
        $this->addItem($result);
        return $result;
    }

    protected function render() {
        $result = '<ul class="' . $this->getName() . '"><li class="separator"></li>';
        foreach ($this->getItems() as $item) {
            $result .= '<li>' . $item->toHtml() . '</li>';
        }
        return $result . '</ul>';
    }

}